from sqlalchemy import Column, Integer, String, DateTime, func
from database import Base  # 你已有的 Base


class Message(Base):
    __tablename__ = "messages"
    __table_args__ = {'comment': '信息表'}

    id = Column(Integer, primary_key=True, index=True)
    title = Column(String(100), comment="信息头")  # 信息头
    content = Column(String(1000), comment="信息体")
    type = Column(String(20), default="类型", comment="信息级别")  # info / warning / error
    status = Column(String(20), default="unread", comment="是否已读")  # unread / read
    created_at = Column(DateTime, default=func.now(), comment="创建时间")


class UserMessage(Base):
    __tablename__ = "user_messages"
    __table_args__ = {'comment': '用户与消息关联表'}

    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, index=True, comment="用户ID")
    message_id = Column(Integer, index=True, comment="消息ID")
    status = Column(String(20), default="unread", comment="是否已读")  # unread / read
    read_at = Column(DateTime, default=func.now(), comment="阅读时间")
